package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.ConvolutionFilter;
	import flash.geom.*;
	
	public class MeanAction extends AbstractAction
	{	
		private var size:int;
			
		public function MeanAction(size:int)
		{
			this.size = size;	
		}
		
		public override function getDescription():String
		{
			return "Mean Filter " + this.size + "x" + this.size;
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var ret:BitmapData = old.clone();
			var len:int = this.size * this.size;
			var arr:Array = new Array(len);
			for(var i:int = 0; i < len; i++)
			{
				arr[i] = 1;
			}
			var filter:ConvolutionFilter = new ConvolutionFilter(this.size, this.size, arr, len);
			ret.applyFilter(ret, ret.rect, new Point(0, 0), filter);
			return ret;
		}
	}
}